checkToken();
function checkToken() {
	var systoken = sessionStorage.getItem('systoken');
	if(!systoken) {
		alert("请先登录!")
		window.location.href = "login.html"
	}
}

var URLS = path + "/grade/getGrade";
layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery','form'], function() {
    var laypage = layui.laypage,
        form = layui.form,
        layer = layui.layer,
        $ = layui.$,
        laydate = layui.laydate;
    var table = layui.table;
    laydate.render({
        elem: '.createTime',
        type: 'datetime'
    });
    laydate.render({
        elem: '.updateTime',
        type: 'datetime'
    });

    form.on("select(pids)",function(){
        if($(".gradeType option:selected").val()==0){
            URLS = path + "/grade/querySimulatorGrade";    
             $("#controlType").find("option").remove();
             $("#controlType").find("optgroup").remove();
             $("#controlType").append( "<option value=\"\">请选择培训科目</option>",
                                        "<option value=\"6\">机场管制基础模拟机</option>",
                                        "<option value=\"7\">程序管制基础模拟机</option>",
       								    "<option value=\"8\">雷达管制基础模拟机</option>");
			
           /*  $(".bianhao").css("display","block");*/
           
            shicaochengji()
        }else if ($(".gradeType option:selected").val()==1) {
            URLS = path + "/grade/getGrade";
            /* $(".bianhao").css("display","none");*/
            $("#controlType").find("option").remove();
            $("#controlType").append( "<option value=\"\">请选择培训科目</option>",
                "<option value=\"1\">机场管制理论</option>",
                "<option value=\"2\">程序管制理论</option>",
                "<option value=\"3\">空管基础理论</option>",
                "<optgroup label=\"雷达管制理论\">",
                "<option value=\"4\">雷达原理</option>",
                "<option value=\"5\">雷达管制</option>",
               " </optgroup>"
            );
            lilunchengji()
        }
        form.render('select');     
    })



    $(".btns").click(function() {
        if ($(".gradeType option:selected").val() == 0) {
            shicaochengji()
        } else {
            lilunchengji()
        }
    })
})

lilunchengji();
function lilunchengji() {
	var name = sessionStorage.getItem('name');
	var type = $(".type option:selected").val();;
	var startTime = $(".startTimes").val();
	var endTime = $(".endTimes").val();
	var courseName=$(".theoryName").val();
	var courseType=$(".courseType option:selected").val();
	// var trainingType=$(".trainingType option:selected").val();
	var controlType = $("#controlType option:selected").val();
	layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery','form'], function() {
        var laypage = layui.laypage,
            layer = layui.layer,
            $ = layui.$
        var table = layui.table;
	    var param = {
            // trainingType:trainingType,
	    	courseName:courseName,
            courseType:courseType,
	    	controlType:controlType,
			name: name,
			type:1,
			stamp: new Date().getTime(),
			startDate: startTime,
			endDate: endTime,
			version: 0,
			visit_plat: 0,
			visit_type: 0,
			is_used: 0
		};
		var defaultpageSise = 10;
		window.ins1 = _render(defaultpageSise);
		function _render(pageSize) {
			var width = $(document).width();
			table.render({
				elem: '#stuTest',
				height: 600,
				title: '用户数据表',
				method: 'post',
				url: URLS,
				page: true,
				where: {param: JSON.stringify(param)},
				headers: {Authorization: sessionStorage.getItem('systoken')},
				skin: 'row',
				even: true,
				autoSort: false,
				loading: true,
				parseData: function(res) {
                    var data = res.rows
                    var msg = '';
                    if (res.status == '000') {
                        msg = res.info;
                        for(i = 0; i < data.length; i++) {
                            var courseType=data[i].courseType;
                            switch (courseType) {
                                case 0:
                                    data[i].courseType = '岗前培训'
                                    break;
                                case 1:
                                    data[i].courseType = '岗位培训'
                                    break;
                                case 2:
                                    data[i].courseType = '复习'
                                    break;
                                case 3:
                                    data[i].courseType = '熟练'
                                    break;
                                case 4:
                                    data[i].courseType = '附加'
                                    break;
                                case 5:
                                    data[i].courseType = '补习'
                                    break;
                                case 6:
                                    data[i].courseType = '追加'
                                    break;
                            }
                            var cType=data[i].controlType;
                            // if (cType == 0) {
                            // 	data[i].controlType = '雷达管制理论';
                            // }
                            if (cType == 1) {
                                data[i].controlType = '机场管制理论';
                            } else if (cType == 2) {
                                data[i].controlType = '程序管制理论';
                            } else if (cType == 3) {
                                data[i].controlType = '空中管制理论';
                            } else if (cType == 4) {
                                data[i].controlType = '雷达原理';
                            } else if (cType == 5) {
                                data[i].controlType = '雷达管制';
                            }
                            var rofession=data[i].rofession
                            if (rofession == 0) {
                                data[i].rofession = '管制';
                            } else if (rofession == 1) {
                                data[i].rofession = '气象';
                            } else if (rofession == 2) {
                                data[i].rofession = '通导';
                            }
                            var type=data[i].type
                            if (type == 0) {
                                data[i].type = '模拟机成绩';
                            } else if (type == 1) {
                                data[i].type = '理论成绩';
                            }
                        }
                    } else if(res.status == '001'){
                        layer.msg("该学员不存在")
                    }else if(res.status == '007'){
                        layer.msg("后台数据为空")
                    }else if(res.status == '002'){
                        layer.msg("后台处理异常")
                    }else if(res.status == "401") {
                        layer.msg("用户已过期，请重新登录")
                        setTimeout("parent.window.location.href='../../login.html'",3000)
                    }
					return {
						"code": res.status,
						"msg": res.rows,
						"count": res.total,
						"data": res.rows
					};
				},
				done: function(res) {
					// $('#inp').val(pageSize);
					// $("#inp").on('blur', function() {
					// 	var inputVal = $("#inp").val();
					// 	_render(inputVal);
					// });
				},
				totalRow: true,
				limit: 30,
				width: width * 0.9,
				cols: [
					[
                        // {field:'year', title:'年份', align:'center'},
                        {field: 'type', title: '课程类型',align: 'center',width: '100' },
                        {field: 'courseType', title: '培训类别',align: 'center',width: '100'},
                        // {field: 'rofession', title: '专业',align: 'center',width: '100'},
                        {field: 'controlType', title: '培训科目',align: 'center',width: '100'},
                        // {field: 'name', title: '学员姓名',align: 'center',width: '100'},
                        {field: 'grade', title: '考试成绩',align: 'center',width: '100'},
                        {field: 'makeUpGrade', title: '补考成绩',align: 'center',width: '100'},
                        {field: 'examDate', title: '考试日期',align: 'center',width: '100'},
                        // {field: 'createTime', title: '导入时间',align: 'center',width: '100'}
					]
				],
					page: true,
			limit: pageSize
			});
		};
	})
}

function shicaochengji() {
    var name = sessionStorage.getItem('name');
    var type = $(".type option:selected").val();
    var startTime = $(".startTimes").val();
    var endTime = $(".endTimes").val();
    var courseName=$(".theoryName").val();
    var courseType=$(".courseType option:selected").val();
    var controlType = $("#controlType option:selected").val();
    layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery','form'], function() {
        var laypage = layui.laypage,
            $ = layui.$
        var table = layui.table;
        var param = {
            courseName:courseName,
            courseType:courseType,
            controlType:controlType,
            name: name,
            type:0,
            stamp: new Date().getTime(),
            startDate: startTime,
            endDate: endTime,
            version: 0,
            visitPlat: 0,
            visitType: 0,
            isUsed: 0
        };

        var defaultpageSise = 10;
        window.ins1 = _render(defaultpageSise);
        function _render(pageSize) {
            var width = $(document).width();
            table.render({
                elem: '#stuTest',
                height: 600,
                title: '用户数据表',
                method: 'post',
                url: URLS,
                page: true,
                where: {param: JSON.stringify(param)},
                headers: {Authorization: sessionStorage.getItem('systoken')},
                skin: 'row',
                even: true,
                autoSort: false,
                loading: true,
                parseData: function(res) {
                    var msg = '';
                    if(res.status == '000') {
                        var ros= res.rows
                        if(ros == null){
                            layer.msg("没有数据")
                        }
                        for (var i = 0 ; i < ros.length; i++){
                            if(ros.length == null){
                                alert("没有数据")
                            }else{
                                if ( ros[i].courseType == 0) {
                                    ros[i].courseType = '岗前培训';
                                } else if ( ros[i].courseType == 1) {
                                    ros[i].courseType = '岗位培训';
                                } else if ( ros[i].courseType == 2) {
                                    ros[i].courseType = '复习';
                                } else if ( ros[i].courseType == 3) {
                                    ros[i].courseType = '熟练';
                                } else if ( ros[i].courseType == 4) {
                                    ros[i].courseType = '附加';
                                } else if ( ros[i].courseType == 5) {
                                    ros[i].courseType = '补习';
                                } else if ( ros[i].courseType == 6) {
                                    ros[i].courseType = '追加';
                                }
                                var rofession = res.rows[i].rofession;
                                if (rofession == 0) {
                                    ros[i].rofession = '管制';
                                } else if (cType == 1) {
                                    ros[i].rofession = '气象';
                                } else if (cType == 2) {
                                    ros[i].rofession = '通导';
                                }
                                if(ros[i].controlType == "6"){
                                    ros[i].controlType = "机场管制基础模拟机"
                                }else if(ros[i].controlType == "7"){
                                    ros[i].controlType = "程序管制基础模拟机"
                                }else if(ros[i].controlType == "8"){
                                    ros[i].controlType = "雷达管制基础模拟机"
                                }
                            }

                        }
                    } else if(res.rows == '后台数据为空') {
                        msg = '数据为空';
                    } else if (res.status == '401') {
                        msg = '请您重新登录！';
                    }
                    return {
                        "code": res.status,
                        "msg": res.rows,
                        "count": res.total,
                        "data": res.rows
                    };
                },
                done: function(res) {
                },
                totalRow: true,
                limit: 30,
                width: width * 0.9,
                cols: [
                    [
                        // {field:'year', title:'年份', align:'center'},
                        {field:'controlType', title:'课程类型', align:'center',width:100},
                        {field: 'courseType', title: '培训类别', align:'center',width:100},
                        // {field: 'rofession', title: '专业', align:'center'},
                        {field: 'controlType', title: '培训科目', align:'center',width:100},
                        // {field: 'name', title: '学员姓名', align:'center'},
                        {field: 'gradeA', title: '考试成绩A', align:'center',width:100},
                        {field: 'gradeB', title: '考试成绩B', align:'center',width:100},
                        {field: 'gradeC', title: '考试成绩C', align:'center',width:100},
                        {field: 'gradeD', title: '考试成绩D', align:'center',width:100},
                        {field: 'makeUpGradeA', title: '补试成绩A', align:'center',width:100},
                        {field: 'makeUpGradeB', title: '补试成绩B', align:'center',width:100},
                        {field: 'makeUpGradeC', title: '补试成绩C', align:'center',width:100},
                        {field: 'makeUpGradeD', title: '补试成绩D', align:'center',width:100},
                        {field: 'examDate', title: '考试日期', align:'center',width:100},
                    ]
                ],
                page: true,
                limit: pageSize,
                loading: true //请求数据时，是否显示loading
            });
        };
    })
}

sessionStorage.removeItem("menu");
sessionStorage.removeItem("curMenu");